import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)

export default new Vuex.Store({
    state: {
        sellerInfo: null,
        memberInfoPt: null,
        memberInfoSj: null,
        czInfo: null,
        fxrId:0,
        openid:null
    },
    getters: {
        getSellerId: state => {
            if (state.sellerInfo == null) {
                // state.sellerInfo = JSON.parse(localStorage.getItem("userinfo"));
                // if(state.sellerInfo == null){
                //     return 0;
                // }
                return 0;
            }
            return state.sellerInfo.id;
        },
        getSellerName: state => {
            if (state.sellerInfo == null) {
                return "";
            } else {
                return state.sellerInfo.name;
            }
        },
        getMemberPtId: state => {
            if (state.memberInfoPt == null) {
                return 0;
            } else {
                return state.memberInfoPt.id;
            }
        },
        getMemberPtOpenId: state => {
            if (state.memberInfoPt == null) {
                return null;
            } else {
                return state.memberInfoPt.weixbh;
            }
        },
        getOpenId:state=>{
            return state.openid;
        },
        getCzId: state => {
            if (state.czInfo == null) {
                return 0;
            } else {
                return state.czInfo.id;
            }
        },
        getFxrId: state => {
            
                return state.fxrId;
            
        },

    },
    mutations: {
        addSellerInfo: (state, info) => {
            state.sellerInfo = info;
            // localStorage.setItem("userinfo",JSON.stringify(info));
        },
        addMemberInfoPt: (state, info) => {
            state.memberInfoPt = info;
        },
        addMemberInfoSj: (state, info) => {
            state.memberInfoSj = info;
        },
        addCzInfo: (state, info) => {
          
            state.czInfo = info;
        },
        addFxrId:(state,id)=>{
            state.fxrId = id;
        },
        setOpenid:(state,openid)=>{
            state.openid = openid;
        }
        
    }
})

